﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Kcadastro.classes;

namespace Kcadastro.adm
{
    public partial class empresas_list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //TODO: BEGIN Seleciona Link Serviços
            if (this.Master is kcadastro)
            {
                ((kcadastro)this.Page.Master).SelecionaPagina(FW.utils.enumPaginas.Empresas);
            }
            //TODO:END
            masterPageKcad m = Master as masterPageKcad;
            m.idFerr = 6;
            if (!IsPostBack)
            {
                carregar();
            }
        }

        private void carregar()
        {
            empresas emps = new empresas();
            //gv_lista.PageIndex = e.NewPageIndex;
            gv_lista.DataSource = emps.listarEmpresas();//
            gv_lista.DataBind();
            emps = null;
        }

        protected void gv_lista_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToString() == "visualizar")
            {
                int ind = Convert.ToInt32(e.CommandArgument);
                DataKey data = gv_lista.DataKeys[ind];
                Session.Add("IDeemp", data.Values["PK_IDemp"].ToString());
                Response.Redirect("empresas_edit.aspx", true); //?id=" + data.Values["PK_IDos"].ToString()
            }
        }

        protected void gv_lista_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            empresas emps = new empresas();
            gv_lista.PageIndex = e.NewPageIndex;
            gv_lista.DataSource = emps.listarEmpresas();//
            gv_lista.DataBind();
            emps = null;
        }

        protected void lk_novaEmpresa_Click(object sender, EventArgs e)
        {
            Session.Add("IDeemp", "");
            Response.Redirect("empresas_edit.aspx", true); 
        }
    }
}